package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.User;
import com.example.mapper.UserMapper;
import com.example.service.IUserService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Date 2022/9/8
 * @Description
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public IPage<User> getUsers(int currentPage, int pageSize, User user) {
        LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
        lqw.like(Strings.isNotBlank(user.getUsername()), User::getUsername, user.getUsername());
        lqw.like(Strings.isNotBlank(user.getStatus()), User::getStatus, user.getStatus());
        lqw.like(Strings.isNotBlank(user.getPhone()), User::getPhone, user.getPhone());
        IPage<User> page = new Page<>(currentPage, pageSize);
        userMapper.selectPage(page, lqw);
        return page;
    }

    @Override
    public User getUser(String username) {
        return userMapper.getUser(username);
    }
}
